//
//  WSOrderDetailSectionHeaderView.m
//  FD
//
//  Created by xiaofang wang on 2019/1/9.
//  Copyright © 2019年 ZhiYuan Network. All rights reserved.
//

#import "WSOrderDetailSectionHeaderView.h"

//model
#import "WSOrderSectionModel.h"

@interface WSOrderDetailSectionHeaderView()
/**bgview*/
@property (nonatomic, strong) UIView *bgView;

/**标题*/
@property (nonatomic, strong) UILabel *biaotiLb;
/**价格*/
@property (nonatomic, strong) UILabel *pricelLb;
/**灰色的线*/
@property (nonatomic, strong) UIView *lightGrayLine;

@end

@implementation WSOrderDetailSectionHeaderView

- (instancetype)initWithReuseIdentifier:(NSString *)reuseIdentifier {
    self = [super initWithReuseIdentifier:reuseIdentifier];
    if (self) {
        [self setupUI];
    }
    return self;
}

- (void)setupUI {
    [self.contentView addSubview:self.bgView];
    [self.bgView addSubview:self.biaotiLb];
    [self.bgView addSubview:self.pricelLb];
    [self.bgView addSubview:self.lightGrayLine];//线
}


#pragma mark - 设置数据
- (void)setSectionModel:(WSOrderSectionModel *)sectionModel {
    _sectionModel = sectionModel;

    //develop 2019-1-9 what are you doing ?
    //判断是否是第一个数据 @"餐品信息"
    NSString *priceStr = [NSString stringWithFormat:@"%@",sectionModel.price];
    NSString *quantityStr = [NSString stringWithFormat:@"%@",sectionModel.quantity];
    if ([NSString isEmptyString:priceStr] || [NSString isEmptyString:quantityStr]) {
        self.biaotiLb.textColor = [UIColor blackColor];
        self.pricelLb.hidden = YES;
    }
    
    self.biaotiLb.text = sectionModel.title;
    //    self.pricelLb.text = [NSString stringWithFormat:@"€ %.1f x%@",[sectionModel.price floatValue],sectionModel.quantity];

    //2019-2-21 要显示的价格=price+配料累加和
    CGFloat p = [sectionModel.price floatValue] + sectionModel.ingredientSumPrice;
    self.pricelLb.text = [NSString stringWithFormat:@"€ %.1f x%@",p,sectionModel.quantity];

}

- (void)layoutSubviews {
    [super layoutSubviews];
    
    [self.bgView mas_makeConstraints:^(MASConstraintMaker *make) {
        make.edges.equalTo(self.contentView);
    }];
    
    [self.biaotiLb mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.equalTo(self.bgView.mas_left).offset(15);
        make.right.equalTo(self.pricelLb.mas_left).offset(-5);
        make.height.mas_equalTo(30);
        make.centerY.equalTo(self.bgView.mas_centerY);
    }];
    
    [self.pricelLb mas_makeConstraints:^(MASConstraintMaker *make) {
        make.right.equalTo(self.bgView.mas_right).offset(-15);
        make.centerY.equalTo(self.bgView.mas_centerY);
        make.height.mas_equalTo(30);
        make.width.mas_greaterThanOrEqualTo(80);
    }];
    
    [self.lightGrayLine mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.equalTo(self.bgView.mas_left).offset(15);
        make.right.equalTo(self.bgView.mas_right).offset(-15);
        make.height.mas_equalTo(1);
        make.bottom.equalTo(self.bgView.mas_bottom);
    }];
}


#pragma mark - getter
- (UIView *)bgView {
    if (!_bgView) {
        _bgView = [UIView new];
        _bgView.backgroundColor = [UIColor whiteColor];
    }
    return _bgView;
}

- (UILabel *)biaotiLb {
    if (!_biaotiLb) {
        _biaotiLb = [[UILabel alloc] init];
        _biaotiLb.textColor = kLightGrayTextColor;
        _biaotiLb.font = [UIFont systemFontOfSize:15.00];
    }
    return _biaotiLb;
}
- (UILabel *)pricelLb {
    if (!_pricelLb) {
        _pricelLb = [UILabel new];
        _pricelLb.textAlignment = NSTextAlignmentRight;
        _pricelLb.font = [UIFont systemFontOfSize:15.0];
    }
    return _pricelLb;
}

//线
- (UIView *)lightGrayLine {
    if (!_lightGrayLine) {
        _lightGrayLine = [UIView new];
        _lightGrayLine.backgroundColor = kMainLightGrayColor;
    }
    return _lightGrayLine;
}
@end
